package cn.funeralobjects.minecraft;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * Spring应用入口
 *
 * @author FuneralObjects
 * Create date: 2020/11/11 7:44 AM
 */
@SpringBootApplication
public class Application {

    private static ConfigurableApplicationContext CONTEXT;

    public static void main(String[] args) {
        CONTEXT = SpringApplication.run(Application.class, args);
    }

    public synchronized static void stop() {
        if (CONTEXT.isActive()) {
            CONTEXT.close();
        }
    }

    public synchronized static <Bean> Bean getBean(Class<Bean> beanClass) {
        if (CONTEXT.isActive()) {
            return CONTEXT.getBean(beanClass);
        }
        return null;
    }


}
